package com.my.study.structures.sort;

import java.util.Arrays;

/**
 * @author Carlos
 * @version 1.0
 * @Description 选择排序
 *
 * 基本思想：
 *
 *
 * @date 2021/7/12 22:49
 **/
public class SelectSort {

    public static void main(String[] args) {

        int[] arr = {2,23,1,323,12,-1};
        sort(arr);
    }

    private static void sort(int[] arr) {
        int len = arr.length - 1;
        for (int i = 0; i < len; i++) {
            int minIndex = i;
            int min = arr[i];
            for (int j = i + 1; j < arr.length; j++) {
                // 降序就是min < arr[j]
                if (min > arr[j]) {
                    min = arr[j];
                    minIndex = j;
                }
            }

            if (minIndex != i) {
                arr[minIndex] = arr[i];
                arr[i] = min;
            }

            System.out.println("第" + (i+1) + "轮");
            System.out.println(Arrays.toString(arr));
        }
    }

}
